package com.shen.thread.reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Test3 {
    public static void main(String[] args) throws ClassNotFoundException {
        User user = new User();
        Class c1 = user.getClass();

        System.out.println(c1.getName());//包名+类名
        System.out.println(c1.getSimpleName());//类名
        System.out.println("==============");

        //获得类的属性
        Field[] fields = c1.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(field);
        }
        //获得类的方法
        Method[] methods = c1.getMethods();//只获得本类方法
        for (Method method : methods) {
            System.out.println(method);
        }
        Method[] methods1 = c1.getDeclaredMethods();//获得本类及父类的public方法

        //获得指定构造器
        Constructor[] constructors = c1.getDeclaredConstructors();
    }
}
